package com.cyh.pangu.leetcode;

/**
 * @author cuiyh9
 * @date 2020/8/26
 */
public class LeetCode283 {
    public void moveZeroes(int[] nums) {
        int numsLength = nums.length;
        if (numsLength == 0) {
            return;
        }
        for (int i = 0, j = 1 ; i < numsLength && j < numsLength; i++, j++) {
            if (nums[i] == 0) {
                while (j < numsLength) {
                    if (nums[j] != 0) {
                        nums[i] = nums[j];
                        nums[j] = 0;
                        break;
                    } else {
                        j++;
                    }
                }


            }
        }

    }

    public static void main(String[] args) {
        int[] nums = {0,1,0,3,12};
        LeetCode283 leetCode283 = new LeetCode283();
        leetCode283.moveZeroes(nums);
        StringBuilder sb = new StringBuilder();
        for (int num : nums) {
            sb.append(num + ",");
        }
        System.out.println(sb.toString());
    }
}
